import { _decorator, Component, Node, tween, Vec3 } from 'cc';
import { DEV } from 'cc/env';
const { ccclass, property } = _decorator;

import EachCard from './EachCard';

@ccclass('CardCtrl')
export class CardCtrl extends Component {

    private _handCardsParent: Node|null;//手牌节点
    private _showCardsParent: Node|null;//出牌显示节点
    private _chooseCards: Node[] = [];

    start() {
        this._handCardsParent = this.node.getChildByName("cardLayout");
        this._showCardsParent = this.node.getChildByName("showCardsParent");

    }

    onPlayBtn() {
        console.log("出牌-------------")
        let pokers = this._handCardsParent.children;

        // console.log("pokers: ", pokers)
        // console.log("pokers[0]: ", pokers[0])
        // console.log("SliderSelector: ", SliderSelector.)

        this._updateCard()
    }

    /**更新牌状态 */
    private _updateCard(): void {
        
        this._chooseCards = []
        let tweenDuration: number = 0.01;

        // console.log("前this.SelectedCards: ", this.SelectedCards)
        let temp_o: EachCard;
        this._handCardsParent.children.forEach((node_o, idx)=> {
            temp_o = node_o.getComponent(EachCard);

            console.log("temp_o.rise_b: ", temp_o.rise_b)
            if (temp_o.rise_b) {
                
                console.log("出牌: ", temp_o)
                tween(node_o)
                .to(tweenDuration, { position: new Vec3(node_o.position.x, this._showCardsParent.position.y, node_o.position.z) })
                .call(()=>{
                    this._handCardsParent.removeChild(node_o)
                    this._showCardsParent.addChild(node_o)
                })
                .start();

                //出的牌就删除掉节点
                // if (temp_o.isValid) temp_o.destroy()
            }
        });


        // let t1 = tween(this.node)
        //     .to(tweenDuration, { position: new Vec3(0, 10, 0) })

        // let t2 = tween(this.node)
        //     .to(tweenDuration, { position: new Vec3(0, -10, 0) })

        // tween(this._showCardsParent).parallel(t1, t2).start(); // 将 t1 和 t2 转化为并行的缓动并加入当前的缓动

        console.log("后this._handCardsParent.children: ", this._handCardsParent.children)
        console.log("后this._showCardsParent.children: ", this._showCardsParent.children)
    }

}


